package com.controller;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dao.AuctionDao;
import com.dao.FeedbackDao;
import com.dao.UserDao;
import com.mybatis.po.Auction;
import com.mybatis.po.Feedback;
import com.mybatis.po.User;
@Controller
public class UserController {
	@Autowired
	public UserDao userDao;
	@RequestMapping("/userLogin")
	@ResponseBody
	public Map<String, List> returnAction(User user) {
		Map<String,List> map = new HashMap<String, List>();
		System.out.print("这个特殊的的"+user.getPassword());

		List<User> list = userDao.selectUser(user);
		
		System.out.print("这个xxx的的"+list.size());
		map.put("arr", list);
		return map;
	}
	@RequestMapping("/forgetPassword")
	@ResponseBody
	public Map<String, List> forPassord(User user) {
		Map<String,List> map = new HashMap<String, List>();
		System.out.print("这个特殊的的"+user.getPassword());
		List<User> list = userDao.selectUser(user);
		map.put("arr", list);
		return map;
	}
	@RequestMapping("/userRegister")
	@ResponseBody
	public Map<String, String> registerUser(User user) {
		Map<String,String> map = new HashMap<String, String>();
		System.out.print("这个特殊的的"+user.getPassword());
		int num = userDao.registerUser(user);
		if(num == 1) {
			map.put("state", "1");
		}else {
			map.put("state", "0");
		}
		return map;
	}
	@RequestMapping("/commentUser")
	@ResponseBody
	public Map<String, String> commentUser(User user) {
		Map<String,String> map = new HashMap<String, String>();
		List<User> listUser = userDao.selectUserById(user);
		System.out.print("这个特殊的的"+user.getPassword());
		user.setCredit(listUser.get(0).getCredit()-2);
		int num = userDao.comment(user);
		if(num == 1) {
			map.put("state", "1");
		}else {
			map.put("state", "0");
		}
		return map;
	}
	
}
